using HKB.Common;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class Shop_PayType
	{
		private Conn conn = null;
		private Pagination _pageHand = null;
		protected Pagination pageHand
		{
			get
			{
				Pagination pageHand;
				if (this._pageHand == null)
				{
					this._pageHand = new Pagination();
					this._pageHand.SQL_CloseTablePre = false;
					this._pageHand.SQL_Fields = "*,(SELECT UserName From HL_User Where HL_User.UserID=HLShop_PayType.UserID) AS UserName";
					this._pageHand.P_Object = Language.GetAdminMsg("PayType/Name");
					pageHand = this._pageHand;
				}
				else
				{
					pageHand = this._pageHand;
				}
				return pageHand;
			}
		}
		public Shop_PayType(Conn _conn)
		{
			this.conn = _conn;
		}
		public Shop_PayType()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public DataTable GetAllPayType(int indexpage, int maxperpage, string wherestr, string orderbystr)
		{
			return this.pageHand.GetDataTable("HLShop_PayType", indexpage, maxperpage, "TypeID", wherestr, orderbystr, this.conn, null);
		}
		public DataTable GetAllPayType(int indexpage, int maxperpage, string wherestr, string orderbystr, params IDbDataParameter[] param)
		{
			return this.pageHand.GetDataTable("HLShop_PayType", indexpage, maxperpage, "TypeID", wherestr, orderbystr, this.conn, param);
		}
		public string GetPagePanel(string linkHead)
		{
			this.pageHand.P_LinkHead = linkHead;
			return this.pageHand.ShowPagePanel();
		}
		public DataTable GetTypeByID(int TypeID)
		{
			return this.conn.GetDataTable("SELECT * From [HLShop_PayType] Where TypeID=" + TypeID);
		}
		public DataTable GetOrderByOrderFormNum(string OrderFormNum)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@OrderFormNum", DbType.String, OrderFormNum);
			return this.conn.GetDataTable("SELECT * From [HLShop_Order] Left Join [HLShop_OrderItem] On HLShop_OrderItem.OrderFormID=HLShop_Order.OrderFormID Where (HLShop_Order.OrderFormNum = @OrderFormNum) Order By HLShop_Order.OrderFormID Desc", new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetTypeByUserID(string OrderFormNum)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@OrderFormNum", DbType.String, OrderFormNum);
			return this.conn.GetDataTable("SELECT * From [HLShop_Order] left Join [HLShop_PayType] On HLShop_PayType.UserID=HLShop_Order.UserID Where (HLShop_Order.OrderFormNum = @OrderFormNum) Order By HLShop_Order.OrderFormID Desc", new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public int CountUserPayTypeNum(int UserID)
		{
			return this.conn.ExecuteCount("SELECT count(*) From [HLShop_PayType] Where UserID=" + UserID);
		}
		public DataTable GetPayTypeByUserID(int UserID)
		{
			return this.conn.GetDataTable("SELECT * From [HLShop_PayType] Where UserID=" + UserID);
		}
		public DataTable GetFromOnlinePaySeting_ByUserID(int sellerID)
		{
			return this.conn.GetDataTable("SELECT * From [HL_OnlinePaySeting] Where userID=" + sellerID);
		}
		public DataTable GetUnDisabledPayTypeByUserID(int UserID)
		{
			return this.conn.GetDataTable("SELECT * From [HLShop_PayType] Where IsDisabled=0 and UserID=" + UserID);
		}
		public DataTable GetOnLinePayTypeByUserID(int UserID)
		{
			return this.conn.GetDataTable("SELECT * From [HLShop_PayType] Where IsDisabled=0 and PayType=0 and UserID=" + UserID);
		}
		public DataTable GetOffLinePayTypeByUserID(int UserID)
		{
			return this.conn.GetDataTable("SELECT * From [HLShop_PayType] Where IsDisabled=0 and PayType=2 and UserID=" + UserID);
		}
		public DataTable GetPayTypeByUserIDTypeID(int UserID, int TypeID)
		{
			string arg = "";
			if (TypeID > 0)
			{
				arg = " and TypeID=" + TypeID;
			}
			return this.conn.GetDataTable("SELECT * From [HLShop_PayType] Where UserID=" + UserID + arg);
		}
		public DataTable GetPayTypeByUserIDTypeID(int UserID, string TypeID)
		{
			string arg = "";
			if (!string.IsNullOrEmpty(TypeID))
			{
				arg = " and TypeID in(" + TypeID + ")";
			}
			return this.conn.GetDataTable("SELECT * From [HLShop_PayType] Where IsDisabled=0 and UserID=" + UserID + arg);
		}
		public DataTable GetShousuPay(int UserId)
		{
			DataTable result;
			if (UserId > 0)
			{
				result = this.conn.GetDataTable("select paytip from HL_Group where GroupID=(select GroupID from HL_User where UserID=" + UserId.ToString() + ")");
			}
			else
			{
				result = null;
			}
			return result;
		}
		public DataTable GetPayTypeByOnlinePay(string OnlinePay)
		{
			return this.conn.GetDataTable("SELECT * From [HLShop_PayType] Where OnlinePay='" + OnlinePay + "'");
		}
		public DataTable GetPayTypeByUserIDTypeName(int UserID, string TypeName)
		{
			DataTable result;
			if (UserID == 0 || TypeName == null)
			{
				result = null;
			}
			else
			{
				IDbDataParameter dbDataParameter = this.conn.CreateParameter("@TypeName", DbType.String, TypeName);
				result = this.conn.GetDataTable("SELECT * From [HLShop_PayType] Where TypeName=@TypeName and UserID=" + UserID, new IDbDataParameter[]
				{
					dbDataParameter
				});
			}
			return result;
		}
		public DataTable GetPayTypeByPayType(int UserID, string PayType)
		{
			return this.conn.GetDataTable(string.Concat(new object[]
			{
				"SELECT * From [HLShop_PayType] Where IsDisabled=0 and PayType in(",
				PayType,
				") and UserID=",
				UserID
			}));
		}
		public bool DeleteType(int TypeID, int UserID)
		{
			bool result;
			if (UserID != 0)
			{
				result = (this.conn.Execute(string.Concat(new object[]
				{
					"DELETE From [HLShop_PayType] Where UserID=",
					UserID,
					" and TypeID=",
					TypeID
				})) >= 1);
			}
			else
			{
				result = (this.conn.Execute("DELETE From [HLShop_PayType] Where TypeID=" + TypeID) >= 1);
			}
			return result;
		}
		public bool AddPayType(string OnlinePay, decimal Discount, string TypeName, int UserID, string PayAccount, string BussinesMD5Key, string BussinessCount, string PayTypeFlag, bool IsDefault, bool IsDisabled, string Intro, int PayType)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@OnlinePay", DbType.String, OnlinePay),
				this.conn.CreateParameter("@Discount", DbType.Decimal, Discount),
				this.conn.CreateParameter("@TypeName", DbType.String, TypeName),
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
				this.conn.CreateParameter("@PayAccount", DbType.String, PayAccount),
				this.conn.CreateParameter("@BussinesMD5Key", DbType.String, BussinesMD5Key),
				this.conn.CreateParameter("@BussinessCount", DbType.String, BussinessCount),
				this.conn.CreateParameter("@PayTypeFlag", DbType.String, PayTypeFlag),
				this.conn.CreateParameter("@IsDefault", DbType.Boolean, IsDefault),
				this.conn.CreateParameter("@IsDisabled", DbType.Boolean, IsDisabled),
				this.conn.CreateParameter("@Intro", DbType.String, Intro),
				this.conn.CreateParameter("@PayType", DbType.Int32, PayType)
			};
			int num = this.conn.Execute("INSERT INTO [HLShop_PayType] ([OnlinePay], \r\n[Discount], [TypeName], [UserID], [PayAccount], [BussinesMD5Key], [BussinessCount], [PayTypeFlag], [IsDefault], [IsDisabled], [Intro], [PayType]) VALUES (@OnlinePay, @Discount, \r\n@TypeName, @UserID, @PayAccount, @BussinesMD5Key, @BussinessCount, @PayTypeFlag, @IsDefault, @IsDisabled, @Intro, @PayType)", parameters);
			return 1 == num;
		}
		public bool UpdatePayType(string OnlinePay, decimal Discount, string TypeName, int UserID, string PayAccount, string BussinesMD5Key, string BussinessCount, string OnlinePayFlag, bool IsDisabled, string Intro, int PayType, int TypeID)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@OnlinePay", DbType.String, OnlinePay),
				this.conn.CreateParameter("@Discount", DbType.Decimal, Discount),
				this.conn.CreateParameter("@TypeName", DbType.String, TypeName),
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
				this.conn.CreateParameter("@PayAccount", DbType.String, PayAccount),
				this.conn.CreateParameter("@BussinesMD5Key", DbType.String, BussinesMD5Key),
				this.conn.CreateParameter("@BussinessCount", DbType.String, BussinessCount),
				this.conn.CreateParameter("@PayTypeFlag", DbType.String, OnlinePayFlag),
				this.conn.CreateParameter("@IsDisabled", DbType.Boolean, IsDisabled),
				this.conn.CreateParameter("@Intro", DbType.String, Intro),
				this.conn.CreateParameter("@PayType", DbType.Int32, PayType),
				this.conn.CreateParameter("@TypeID", DbType.Int32, TypeID)
			};
			int num = this.conn.Execute("UPDATE [HLShop_PayType] SET \r\n            [OnlinePay] = @OnlinePay, [Discount] = @Discount, [TypeName] = @TypeName, \r\n            [UserID] = @UserID, [PayAccount] = @PayAccount, [BussinesMD5Key] = @BussinesMD5Key, [BussinessCount] = @BussinessCount, \r\n            [PayTypeFlag] = @PayTypeFlag, [IsDisabled] = @IsDisabled, [Intro] = @Intro, [PayType] = @PayType WHERE (([TypeID] = @TypeID))", parameters);
			return 1 == num;
		}
		public bool AddPayType(string OnlinePay, decimal Discount, string TypeName, int UserID, string PayAccount, string BussinesMD5Key, string BussinessCount, string PayTypeFlag, bool IsDefault, bool IsDisabled, string Intro, int PayType, string OutlinePay)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@OnlinePay", DbType.String, OnlinePay),
				this.conn.CreateParameter("@Discount", DbType.Decimal, Discount),
				this.conn.CreateParameter("@TypeName", DbType.String, TypeName),
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
				this.conn.CreateParameter("@PayAccount", DbType.String, PayAccount),
				this.conn.CreateParameter("@BussinesMD5Key", DbType.String, BussinesMD5Key),
				this.conn.CreateParameter("@BussinessCount", DbType.String, BussinessCount),
				this.conn.CreateParameter("@PayTypeFlag", DbType.String, PayTypeFlag),
				this.conn.CreateParameter("@IsDefault", DbType.Boolean, IsDefault),
				this.conn.CreateParameter("@IsDisabled", DbType.Boolean, IsDisabled),
				this.conn.CreateParameter("@Intro", DbType.String, Intro),
				this.conn.CreateParameter("@PayType", DbType.Int32, PayType),
				this.conn.CreateParameter("@OutlinePay", DbType.String, OutlinePay)
			};
			int num = this.conn.Execute("INSERT INTO [HLShop_PayType] ([OnlinePay], \r\n[Discount], [TypeName], [UserID], [PayAccount], [BussinesMD5Key], [BussinessCount], [PayTypeFlag], [IsDefault], [IsDisabled], [Intro], [PayType],OutlinePay) VALUES (@OnlinePay, @Discount, \r\n@TypeName, @UserID, @PayAccount, @BussinesMD5Key, @BussinessCount, @PayTypeFlag, @IsDefault, @IsDisabled, @Intro, @PayType,@OutlinePay)", parameters);
			return 1 == num;
		}
		public bool UpdatePayType(string OnlinePay, decimal Discount, string TypeName, int UserID, string PayAccount, string BussinesMD5Key, string BussinessCount, string OnlinePayFlag, bool IsDisabled, string Intro, int PayType, int TypeID, string OutlinePay)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@OnlinePay", DbType.String, OnlinePay),
				this.conn.CreateParameter("@Discount", DbType.Decimal, Discount),
				this.conn.CreateParameter("@TypeName", DbType.String, TypeName),
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
				this.conn.CreateParameter("@PayAccount", DbType.String, PayAccount),
				this.conn.CreateParameter("@BussinesMD5Key", DbType.String, BussinesMD5Key),
				this.conn.CreateParameter("@BussinessCount", DbType.String, BussinessCount),
				this.conn.CreateParameter("@PayTypeFlag", DbType.String, OnlinePayFlag),
				this.conn.CreateParameter("@IsDisabled", DbType.Boolean, IsDisabled),
				this.conn.CreateParameter("@Intro", DbType.String, Intro),
				this.conn.CreateParameter("@PayType", DbType.Int32, PayType),
				this.conn.CreateParameter("@TypeID", DbType.Int32, TypeID),
				this.conn.CreateParameter("@OutlinePay", DbType.String, OutlinePay)
			};
			int num = this.conn.Execute("UPDATE [HLShop_PayType] SET \r\n            [OnlinePay] = @OnlinePay, [Discount] = @Discount, [TypeName] = @TypeName, \r\n            [UserID] = @UserID, [PayAccount] = @PayAccount, [BussinesMD5Key] = @BussinesMD5Key, [BussinessCount] = @BussinessCount, \r\n            [PayTypeFlag] = @PayTypeFlag, [IsDisabled] = @IsDisabled, [Intro] = @Intro, [PayType] = @PayType, [OutlinePay] = @OutlinePay WHERE (([TypeID] = @TypeID))", parameters);
			return 1 == num;
		}
		public bool SetPayTypeAsDefault(int UserID, int TypeID)
		{
			this.conn.BeginTransaction();
			bool result;
			try
			{
				if (UserID <= 0)
				{
					this.conn.ExecuteTransaction("Update [HLShop_PayType] Set IsDefault=0 Where UserID=(Select UserID From HLShop_PayType Where TypeID=" + TypeID + ")");
					this.conn.ExecuteTransaction("Update [HLShop_PayType] Set IsDefault=1 Where TypeID=" + TypeID);
				}
				else
				{
					this.conn.ExecuteTransaction("Update [HLShop_PayType] Set IsDefault=0 Where UserID=" + UserID);
					this.conn.ExecuteTransaction(string.Concat(new object[]
					{
						"Update [HLShop_PayType] Set IsDefault=1 Where UserID=",
						UserID,
						" and TypeID=",
						TypeID
					}));
				}
			}
			catch
			{
				this.conn.Rollback();
				result = false;
				return result;
			}
			this.conn.Commit();
			result = true;
			return result;
		}
		public DataTable GetPayTypeByType(int UserID, int PayType)
		{
			return this.conn.GetDataTable(string.Concat(new object[]
			{
				"SELECT * From [HLShop_PayType] Where PayType=",
				PayType,
				" and UserID=",
				UserID
			}));
		}
		public bool SetDisenabled(bool Disenabled, int PayTypeID)
		{
			int num;
			if (Disenabled)
			{
				num = this.conn.Execute("Update HLShop_PayType set IsDisabled = 1  Where TypeID = " + PayTypeID);
			}
			else
			{
				num = this.conn.Execute("Update HLShop_PayType set IsDisabled = 0  Where TypeID = " + PayTypeID);
			}
			return num > 0;
		}
		public DataTable GetPayTypeByTypeIDUserIDNotDisabled(int TypeID, int UserID)
		{
			return this.conn.GetDataTable(string.Format("SELECT * FROM HLShop_PayType Where TypeID = {0} and UserID = {1} and IsDisabled={2}", TypeID, UserID, 1));
		}
	}
}
